import java.util.Comparator;
import java.util.PriorityQueue;

public class Text {
    public static void main(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(100);
        priorityQueue.offer(2);
        priorityQueue.offer(-2);
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
        System.out.println(priorityQueue.poll());
    }

    public int[] smallestK(int[] arr, int k) {
        int[] ret = new int[k];
        if (arr==null||k<=0){
            return ret;
        }
        imp imp = new imp();
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(imp);
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }

        for (int i = k; i < arr.length; i++) {
            int top=priorityQueue.peek();
            if(top>arr[i]){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        for (int i = 0; i < k; i++) {
            ret[i]=priorityQueue.poll();
        }
        return ret;
    }
}

class imp implements Comparator<Integer> {
    public int compare(Integer o1,Integer o2) {
        return o2-o1;
    }
}
